public class MyQueue {
    static class ListNode{
        public int val;
        public ListNode prev;
        public ListNode next;

        public ListNode(int val) {
            this.val = val;
        }
    }
    public ListNode first;
    public ListNode last;
    public void offer(int val){
        ListNode node = new ListNode(val);
        if (first == null){
            first = last = node;
        }
        else {
            last.next = node;
            node.prev = last;
            last = node;
        }
    }
    public int poll(){
        if(first == null){
            return -1;
        }
        int val = first.val;
        if (first == last){
            first = null;
            last = null;
        }
        else {
            first = first.next;
            first.prev = null;
        }
        return val;
    }
    public int peek(){
        if (first == null){
            return -1;
        }
        else {
            return first.val;
        }
    }
    public int size(){
        ListNode cur = first;
        int size = 0;
        while (cur != null){
            cur = cur.next;
            size++;
        }
        return size;
    }
    public boolean empty(){
        return first == null;
    }
}
